package com.cat.binaryTree;

import java.util.HashSet;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/delete-nodes-from-linked-list-present-in-array/description/
 * @create 2025/9/10 10:11
 * @since JDK17
 */

public class Solution07 {
    public ListNode modifiedList(int[] nums, ListNode head) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        ListNode newList = new ListNode(), p = newList;
        while (head != null) {
            if (!set.contains(head.val)) {
                p = p.next = head;
            }
            head = head.next;
        }
        p.next = null;
        return newList.next;
    }
}
